<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  
  <body>
  这里是通讯录哦~<br>
  你可以选择<br>
  <a href="add.jsp">添加新联系人</a><br>
  <a href="serch.jsp">查询联系人</a><br>
    <%  Connection con;
    	Statement sql;
    	ResultSet rs;
    	try{Class.forName("com.mysql.jdbc.Driver");
    		}
    	catch(Exception e){
    		out.println("忘记把MySQL数据库的JDBC-数据库驱动程序复制到JDK的扩展目录中");
    		}
    	try { 
    		String uri= "jdbc:mysql://localhost:3306/peopletext";
          	String user="root";
          	String password="kamui5201";
          	con=DriverManager.getConnection(uri,user,password);
  			sql=con.createStatement();
          	rs = sql.executeQuery("select *from pinfo");
        
          	out.print("<table border=1>");
          	out.print("<tr>");
            	out.print("<th width=100>"+"姓名");
           	 	out.print("<th width=100>"+"电话");
            	out.print("<th width=100>"+"地址");
            	out.print("<th width=100>"+"相关操作");
          	out.print("</tr>");
          	while(rs.next()){
            	out.print("<tr>");
              	out.print("<td>"+rs.getString(1)+"</td>"); 
              	out.print("<td>"+rs.getString(2)+"</td>");
              	out.print("<td>"+rs.getString(3)+"</td>"); 
              	out.print("<td><a href=\"change.jsp?id="+rs.getString(4)+"\">修改</a>"+" <a href=\"delete.jsp?id="+rs.getString(4)+"\">删除</a>"+"</td>");
              
           	 out.print("</tr>") ; 
          	}
          	out.print("</table>");
          	con.close();
    	}
    	catch(SQLException e){ 
          	out.print(e);
    	}
    %> 
  </body>
</html>
